## looks at the letter writers of the applicants
##
## Cait Unkovic, Maya Sen, Kevin Quinn
##
## 12/20/2014
##


## Table 8

## data from the polmeth application database
x <- read.csv("ExperimentalApplicantsMergedPolmeth.csv",
                        stringsAsFactors=FALSE)

## just female applicants
x <- x[x$sex=="Female",]


x.reject <- x[x$accept == 0,]
x.accept <- x[x$accept == 1,]
x.treat <- x[x$treat == 1,]
x.control <- x[x$treat == 0,]
x.treat.reject <- x.reject[x.reject$treat == 1,]
x.treat.accept <- x.accept[x.accept$treat == 1,]
x.control.reject <- x.reject[x.reject$treat == 0,]
x.control.accept <- x.accept[x.accept$treat == 0,]



output.table <- data.frame(letter.type=c("Networked Letter",
                               "Non-Networked Letter",
                               "No Letter"), treated.female=NA,
                           control.female=NA, rej.treat.female=NA,
                           rej.control.female=NA)

output.table$treated.female[3] <- sum(x.treat$RecLetter==0)
output.table$treated.female[1] <- sum(x.treat$RecNetworked==1)
output.table$treated.female[2] <- sum(x.treat$RecLetter==1) - sum(x.treat$RecNetworked==1)


output.table$control.female[3] <- sum(x.control$RecLetter==0)
output.table$control.female[1] <- sum(x.control$RecNetworked==1)
output.table$control.female[2] <- sum(x.control$RecLetter==1) - sum(x.control$RecNetworked==1)


output.table$rej.treat.female[3] <- sum(x.treat.reject$RecLetter==0)
output.table$rej.treat.female[1] <- sum(x.treat.reject$RecNetworked==1)
output.table$rej.treat.female[2] <- sum(x.treat.reject$RecLetter==1) - sum(x.treat.reject$RecNetworked==1)



output.table$rej.control.female[3] <- sum(x.control.reject$RecLetter==0)
output.table$rej.control.female[1] <- sum(x.control.reject$RecNetworked==1)
output.table$rej.control.female[2] <- sum(x.control.reject$RecLetter==1) - sum(x.control.reject$RecNetworked==1)





library(xtable)

print(xtable(output.table, display=c("s", "s", "f", "f", "f", "f"),
             digits=c(10, 0, 0, 0, 0, 0)),
      include.rownames=FALSE)








## Table 9

## data from the polmeth application database
x <- read.csv("ExperimentalApplicantsMergedPolmeth.csv",
                        stringsAsFactors=FALSE)

## just female applicants
x <- x[x$sex=="Male",]


x.reject <- x[x$accept == 0,]
x.accept <- x[x$accept == 1,]
x.treat <- x[x$treat == 1,]
x.control <- x[x$treat == 0,]
x.treat.reject <- x.reject[x.reject$treat == 1,]
x.treat.accept <- x.accept[x.accept$treat == 1,]
x.control.reject <- x.reject[x.reject$treat == 0,]
x.control.accept <- x.accept[x.accept$treat == 0,]



output.table <- data.frame(letter.type=c("Networked Letter",
                               "Non-Networked Letter",
                               "No Letter"), treated.female=NA,
                           control.female=NA, rej.treat.female=NA,
                           rej.control.female=NA)

output.table$treated.female[3] <- sum(x.treat$RecLetter==0)
output.table$treated.female[1] <- sum(x.treat$RecNetworked==1)
output.table$treated.female[2] <- sum(x.treat$RecLetter==1) - sum(x.treat$RecNetworked==1)


output.table$control.female[3] <- sum(x.control$RecLetter==0)
output.table$control.female[1] <- sum(x.control$RecNetworked==1)
output.table$control.female[2] <- sum(x.control$RecLetter==1) - sum(x.control$RecNetworked==1)


output.table$rej.treat.female[3] <- sum(x.treat.reject$RecLetter==0)
output.table$rej.treat.female[1] <- sum(x.treat.reject$RecNetworked==1)
output.table$rej.treat.female[2] <- sum(x.treat.reject$RecLetter==1) - sum(x.treat.reject$RecNetworked==1)



output.table$rej.control.female[3] <- sum(x.control.reject$RecLetter==0)
output.table$rej.control.female[1] <- sum(x.control.reject$RecNetworked==1)
output.table$rej.control.female[2] <- sum(x.control.reject$RecLetter==1) - sum(x.control.reject$RecNetworked==1)





library(xtable)

print(xtable(output.table, display=c("s", "s", "f", "f", "f", "f"),
             digits=c(10, 0, 0, 0, 0, 0)),
      include.rownames=FALSE)


